#!/bin/bash
#add the file to measure how log the time provsion cost

date +%s > /tmp/provision-start.txt


YUM_SYS=`cat /etc/redhat-release |awk -F" " '{print$(NF-1)}'`
YUM_BASEARCH=`uname -i`

echo "--> Starting Vagrant Pre-provisioning: pre_provision_6.sh..." 

SOURCE_ROOT=..

# Add epel repo 
echo "--> Installing EPEL repo" 
if [ ! -e /etc/yum.repos.d/epel.repo ] && [[ "$YUM_SYS" =~ ^6\..* ]]; then
    echo "Installing EPEL repo..."
    # Note, $YUM_BASEARCH defined in function.sh
    sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/${YUM_BASEARCH}/epel-release-6-8.noarch.rpm
    # Never CLEAN YUM any more, see below
    # NEED_YUM_CLEAN=1
    echo "EPEL repo installed"
elif [ ! -e /etc/yum.repos.d/epel.repo ] && [[ "$YUM_SYS" =~ ^7\..* ]]; then
    echo "Installing EPEL repo..."
    # Note, $YUM_BASEARCH defined in function.sh ,the epel-release-7-5.noarch.rpm is not found now  update it to 7.6
    sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/${YUM_BASEARCH}/e/epel-release-7-6.noarch.rpm
    # Never CLEAN YUM any more, see below
    # NEED_YUM_CLEAN=1
    echo "EPEL repo installed"
fi

echo "--> Install Puppet"
if rpm -aq|grep -q puppet; then
   echo "Puppet ready"
else
   yum install -y puppet
fi

echo "--> Install Rsync"
if rpm -aq|grep -q rsync; then
   echo "Rsync installed"
else
   yum install -y rsync
fi

echo "--> Install Wget"
if rpm -aq|grep -q wget; then
   echo "Wget installed"
else
   yum install -y wget
fi

echo "--> Pre_provision finished in ${SECONDS}s"

